document.addEventListener("DOMContentLoaded", function () {
    class MaskController {
        #maskDiv;  
        #defaultStyles = {
            position: 'fixed',
            top: '0',
            left: '0',
            width: '100%',
            height: '100%',
            backgroundColor: 'rgba(0, 0, 0, 0.5)',
            display: 'none'
        };
        constructor(options = {}) {
            this.#maskDiv = document.createElement('div');
            this.#maskDiv.className = 'mask';
            this.#maskDiv.style.zIndex = '666';
            
            // 合并默认样式和自定义样式
            Object.assign(this.#maskDiv.style, this.#defaultStyles, options);
            document.body.insertBefore(this.#maskDiv, document.body.firstChild);
        }
        
        show() {
            if (this.#maskDiv) {  
                this.#maskDiv.style.display = "block";
            }
            document.body.style.overflow = "hidden";
        }
        
        hide() {
            if (this.#maskDiv) {  
                this.#maskDiv.style.display = "none";
            }
            document.body.style.overflow = "auto";
        }
        toggle() {
            if (this.#maskDiv.style.display === "none" || this.#maskDiv.style.display === "") {
                this.show();
            } else {
                this.hide();
            }
        }
        node() {   
            return this.#maskDiv;
        }
        
        exists() {
            return !!this.#maskDiv;  
        }
    }
    window.masker = new MaskController();
});
